package com.cloud.point.designPattern.controller;

import com.cloud.point.designPattern.builder.IMenu;
import com.cloud.point.designPattern.builder.IMenuImpl;
import com.cloud.point.designPattern.builder.matterImpl.ceiling.LevelTwoCeiling;
import com.cloud.point.designPattern.builder.matterImpl.coat.LevelOneCoat;
import com.cloud.point.designPattern.builder.matterImpl.coat.LevelTwoCoat;
import com.cloud.point.designPattern.builder.matterImpl.tile.LevelOneTile;
import com.cloud.point.designPattern.builder.matterImpl.wood.LevelTwoWood;
import com.cloud.point.designPattern.chainResponsibility.ParamRequest;
import com.cloud.point.designPattern.chainResponsibility.ValidatorManager;
import com.cloud.point.designPattern.observer.ObserverManager;
import com.cloud.point.designPattern.observer.TransferEvent;
import com.cloud.point.designPattern.strategy.DiscountContext;
import com.cloud.point.designPattern.strategy.DiscountType;
import com.cloud.point.designPattern.template.FoodDay;
import com.cloud.point.designPattern.template.impl.CattleWorker;
import com.cloud.point.designPattern.template.impl.Student;
import com.cloud.point.designPattern.template.impl.Teacher;
import java.math.BigDecimal;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 测试类
 *
 * @author 24373
 * @version 1.0
 * @date 2024-06-02 00:16
 */
@Slf4j
@RestController
@RequestMapping("/design")
@AllArgsConstructor
public class TestController {

    private final ValidatorManager validatorManager;
    private final DiscountContext discountContext;
    private final ObserverManager observerManager;

    /**
     * 测试责任链模式
     */
    @GetMapping("valid")
    public void responsibility() {
        validatorManager.checkParam(new ParamRequest());
    }

    /**
     * 测试策略模式
     */
    @GetMapping("strategy")
    public void strategy() {
        BigDecimal bigDecimal = discountContext.payService(DiscountType.ZJ, new BigDecimal("10"));
        log.info("直减价格:{}", bigDecimal);
        BigDecimal bigDecimal2 = discountContext.payService(DiscountType.ZK, new BigDecimal("10"));
        log.info("折扣价格:{}", bigDecimal2);
        BigDecimal bigDecimal3 = discountContext.payService(DiscountType.NULL, new BigDecimal("10"));
        log.info("原价:{}", bigDecimal3);
    }

    /**
     * 测试模板模式
     */
    @GetMapping("template")
    public void template() {
        FoodDay student = new Student();
        student.eat();
        FoodDay teacher = new Teacher();
        teacher.eat();
        FoodDay worker = new CattleWorker();
        worker.eat();
    }

    /**
     * 测试观察者模式
     */
    @GetMapping("observer")
    public void observer() {
        observerManager.notifyObservers(new TransferEvent());
    }

    /**
     * 测试建造者模式
     */
    @GetMapping("builder")
    public void builder() {
        IMenu menu = new IMenuImpl(new BigDecimal("212"), "高端");
        menu.appendCeiling(new LevelTwoCeiling())
                .appendCoat(new LevelOneCoat())
                .appendCoat(new LevelTwoCoat())
                .appendWood(new LevelTwoWood())
                .appendTile(new LevelOneTile())
        ;
        System.out.println(menu.getDetail());
    }

}
